

export default {
    getAddCount(state){
        var arr=[],
        sum=0;
       if(state.shopCart.length!==0){
            state.shopCart.forEach(function(item,index){
                let totalNumber=item.goodsItems.filter(function(element){
                    if(element.isSelect==true){
                        return element.isSelect
                    }
                }).length;
                arr.push(totalNumber)
            })
        }else{
            sum=0
        }
        if(arr.length==0){
            return 
        }else{
            sum=arr.reduce(function(total,num){
                return total+num
            });
        }
        return sum
    },
    getAllPrice(state){
        var price=0,
            arr1=[],
            allPrice=0;
        if(state.shopCart.length!==0){
            state.shopCart.forEach(function(item,index){
                let arr=item.goodsItems.map(function(element){
                    if(element.isSelect==true){
                        return element.count*element.itemDetail.itemPrice
                    }else{
                        return 0
                    }
                })
               if(arr.length==0){
                   return
               }else{
                    price=arr.reduce(function(total,num){
                        if(num!==undefined){
                            return total+num
                        }else{
                            return total;
                        }
                    })
                }    
                arr1.push(price);
            })
        }else{
            allPrice=0;
        }
        // console.log(arr1,8888)
        if(arr1.length==0){
            return
        }else{
            allPrice=arr1.reduce(function(total,num){
                return total+num
            });
        }
        return allPrice
    },
    getCartCount(state){
        return state.shopCart.length
    }
}